package cn.tedu.uep.message.controller;

import cn.tedu.uep.base.response.JsonResult;
import cn.tedu.uep.message.po.dto.MessageCreateParam;
import cn.tedu.uep.message.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.tedu.uep.message.po.vo.MessageVO;

import java.util.List;

@RestController
@RequestMapping("/v1/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 查询消息
     */
    @GetMapping("selectMessage")
    public JsonResult select(@RequestParam("userId") Long userId,
                             @RequestParam("messageStatus") String messageStatus){
        List<MessageVO> list = messageService.select(userId, messageStatus);
        return JsonResult.ok(list);
    }

    /**
     * 新增消息
     */
    @PostMapping("createMessage")
    public JsonResult createMessage(@RequestBody MessageCreateParam param){
        Boolean message = messageService.createMessage(param);
        return message ? JsonResult.ok() : null;
    }

    /**
     * 已读消息（批量已读）
     */
    @PostMapping("readMessage")
    public JsonResult readMessage(@RequestBody List<Long> messageIds){
        //todo:还没测试
        Boolean message = messageService.readMessage(messageIds);
        return message ? JsonResult.ok() : null;
    }
}
